package category.util;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

//싱글톤패턴
public class DatabaseManager {

	private static DatabaseManager instance = new DatabaseManager();
	private SqlSessionFactory factory;
	
	
	private DatabaseManager(){
		//SqlSessionFactory 생성
		InputStream in = null;
		try {
			in = Resources.getResourceAsStream("category/model/dao/config/mybatis-config.xml");
		} catch (IOException e) {
			e.printStackTrace();
		}
		SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
		factory = builder.build(in);
	}
	public static DatabaseManager getInstance(){
		return instance;
	}
	public SqlSessionFactory getSqlSessionFactory(){
		return factory;
	}
}










